<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>字典</title>
</head>
<body>
  <script>
    function Dictionary() {
      this.dataStore = [];
      this.add = add;
      this.find = find;
      this.remove = remove;
      this.showAll = showAll;
      this.count = count;
      this.clear = clear;
    }
    
    function add(key,value) {
      this.dataStore[key] = value;
    }
    
    function find(key) {
      return this.dataStore[key];
    }
    
    function remove(key) {
      delete this.dataStore(key);
    }
    
    function showAll() {
      let dataKey = Object.keys(this.dataStore);
      for (let key in dataKey){
        console.log(`key:${dataKey[key]},value:${this.dataStore[dataKey[key]]}`);

      }
    }
    
    function count() {
      return Object.keys(this.dataStore).length;
    }
    
    function clear() {
      let dataKey = Object.keys(this.dataStore);
      for (let key in dataKey){
        delete this.dataStore[dataKey[key]];
      }
    }

    let books = new Dictionary();
    books.add('科技',122);
    books.add('故事',123);
    books.add('童话',15);

    books.showAll();

  </script>
</body>
</html>